<template>
  <div class="collapse-box">
      <div class="collapse-box-header">
        <div class="left" @click="handleOpen">
          <Icon :type="`ios-arrow-${isOpen? 'down' : 'up'}`" size="16" />
          <span class="title">{{title}}</span>
          <Tooltip transfer theme="light" placement="top" max-width="400" :content="tip" v-if="tip">
            <Icon type="ios-alert-outline" size="16" />
          </Tooltip>
        </div>
        <div class="right"> 
          <slot name="right"></slot>
        </div>
      </div>
      <div class="collapse-box-content" v-show="isOpen">
        <slot></slot>
      </div>
    </div>
</template>
<script setup>
import { ref } from 'vue';

const props = defineProps({
  title: {
    type: String
  },
  tip: {
    type: String
  }
})

const isOpen = ref(true);
const handleOpen = () => {
  isOpen.value = !isOpen.value
}
</script>
<style lang="scss" scoped>
.collapse-box-header {
  margin-bottom: 20px;
  transition: all .2s ease-in;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: space-between;
  .title {
    font-size: 14px;
    color: #333;
    font-weight: bold;
    margin-left: 8px;
    margin-right: 6px;
  }
  
}
.collapse-box-content {
  transition: all .2s ease-in;
}
</style>